<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>promise的使用</title>
</head>

<body>

</body>
<script>
  let p = new Promise((res, rej) => {
    setTimeout(() => {
      let isRight = false
      if (isRight) {
        let data = '数据库的数据'
        res(data)
      } else {
        let err = '数据读取失败'
        rej(err)
      }
    }, 1000)
  })

  p.then(function (value) {
    console.log(value)
  }).catch((value) => {
    console.log(value)
  })



  var q = new Promise((resolve, reject) => {
    //正在进行时。。。。如一些异步操作
    let num = Math.random();
    console.log("打印随机数" + num);
    num > 0.6 ? resolve() : reject();
  }).then(function resolve() {
    console.log("我是resolve函数")
  }, function reject() {
    console.log("我是reject函数")
  })

</script>

</html>